package com.yyge.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

import java.util.Arrays;

/**
 * 跨域解决页面请求CORS
 */
@Configuration
// 跨域过滤器
public class CorsConfig {
 @Bean
 CorsFilter corsFilter () {
   CorsConfiguration configuration = new CorsConfiguration ();
   configuration .setAllowedOrigins (Arrays.asList("http://localhost:9528"));
   configuration .setAllowedMethods (Arrays.asList("*"));
   configuration .setAllowedHeaders (Arrays.asList("*"));
   configuration .setAllowCredentials (true);
   UrlBasedCorsConfigurationSource source = new
   UrlBasedCorsConfigurationSource ();
   source.registerCorsConfiguration ("/**" , configuration);
   return new CorsFilter(source);
 }
}